<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_payment_mode Extends MY_Model
{

	public function __construct()
	{
		parent::__construct();
	
	}
	
	
	// Create
	public function insert_payment_modes($data){
		$this->db->insert('payment_modes', $data); 
		return $this->db->affected_rows() >=1 ? TRUE : FALSE;
	}
	
	// Retrieve
	public function get_payment_plans($id = FALSE){
		if($id == FALSE){
			$q =  $this->db->get('payment_modes');
			return $q->num_rows() >= 1 ? $q->result_array() : FALSE;
		}else{
			$q = $this->db->select('id,payment_mode_name')
					  ->where('id',$id)
					  ->get('payment_modes');
			return $q->num_rows() >= 1 ? $q->row() : FALSE; 
		}
	}

	public function get_payment_plan_id($name = FALSE){
		if($name == FALSE){
			$q =  $this->db->get('payment_modes');
			return $q->num_rows() >= 1 ? $q->result_array() : FALSE;
		}else{
			$q = $this->db->select('id')
					  ->where('payment_mode_name',$name)
					  ->get('payment_modes');
			return $q->num_rows() >= 1 ? $q->row() : FALSE; 
		}
	}
	
	// Update
	public function update_payment_modes($id = FALSE, $data = FALSE)
	{
		if($id != FALSE AND $data != FALSE){
			$this->db->where('id', $id);
			$this->db->update('payment_modes', $data); 
			return $this->db->affected_rows() >=1 ? TRUE : FALSE;
		}else{
			return FALSE;
		}
	}
	
	//Destroy
	public function delete_payment_modes($id = FALSE)
	{
		if($id != FALSE){
			$this->db->where('payment_mode_id', $id);
			$this->db->delete('payment_mode_values'); 
			if( $this->db->affected_rows() >=1 ){ 
				$this->db->where('id', $id);
				$this->db->delete('payment_modes'); 
				return $this->db->affected_rows() >=1 ? TRUE : FALSE;
			}else{
				return FALSE;
			}
		}else{
			return FALSE;
		}
	}
}